package com.xuxiao.mapper;

import com.xuxiao.common.CardAndBalance;
import com.xuxiao.common.CartAndName;
import com.xuxiao.common.NameAndCardID;
import com.xuxiao.entrty.CardInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CardInfoMapper {
    @Insert("Insert into cardinfo (cardID,openDate, openMoney, cardType, balance, pass, customerID) values (#{cardID},#{openDate},#{openMoney},#{cardType},#{balance},#{pass},#{customerID})")
    void insertCard(CardInfo cardInfo);

    @Select("Select cardID, openDate, openMoney, balance, pass,cardType, username FROM cardinfo,userinfo where cardinfo.customerID=userinfo.customerID")
    List<CartAndName> SelectAll();

    @Select("SELECT * FROM cardinfo where cardID=#{id}")
    List<CardInfo> SelectByID(String id);

    void DeleteAll(List<Integer> ids);

    void updateCardBy(CardInfo cardInfo);

    @Select("SELECT * FROM cardinfo where customerID=#{id}")
    List<CardInfo> getCardByUserID(String id);

    @Update("UPDATE cardinfo set balance=balance+#{balance} WHERE cardID=#{cardID}")
    void plusByCard(CardInfo cardInfo);

    @Select("SELECT cardID,balance from cardinfo where customerID=#{id}")
    List<CardAndBalance> getAllCartBalance(String id);

    @Select("SELECT cardID,username from cardinfo,userinfo where cardinfo.customerID=userinfo.customerID")
    List<NameAndCardID> getNameAndCardID(String id);

    @Select("SELECT COUNT(*) FROM cardinfo where cardID=#{cardID} AND pass=#{pass}")
    int IsCorrect(CardInfo cardInfo);
}
